package com.ruoyi.project.system.goodsregion.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.system.goodsregion.domain.GoodsRegion;
import com.ruoyi.project.system.goodsregion.service.IGoodsRegionService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商品禁止发货区域Controller
 * 
 * @author LCL
 * @date 2021-01-05
 */
@Controller
@RequestMapping("/system/goodsregion")
public class GoodsRegionController extends BaseController
{
    private String prefix = "system/goodsregion";

    @Autowired
    private IGoodsRegionService goodsRegionService;

    @RequiresPermissions("system:goodsregion:view")
    @GetMapping()
    public String goodsregion()
    {
        return prefix + "/goodsregion";
    }

    /**
     * 查询商品禁止发货区域列表
     */
    @RequiresPermissions("system:goodsregion:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(GoodsRegion goodsRegion)
    {
        startPage();
        List<GoodsRegion> list = goodsRegionService.selectGoodsRegionList(goodsRegion);
        return getDataTable(list);
    }

    /**
     * 导出商品禁止发货区域列表
     */
    @RequiresPermissions("system:goodsregion:export")
    @Log(title = "商品禁止发货区域", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(GoodsRegion goodsRegion)
    {
        List<GoodsRegion> list = goodsRegionService.selectGoodsRegionList(goodsRegion);
        ExcelUtil<GoodsRegion> util = new ExcelUtil<GoodsRegion>(GoodsRegion.class);
        return util.exportExcel(list, "goodsregion");
    }

    /**
     * 新增商品禁止发货区域
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存商品禁止发货区域
     */
    @RequiresPermissions("system:goodsregion:add")
    @Log(title = "商品禁止发货区域", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(GoodsRegion goodsRegion)
    {
        return toAjax(goodsRegionService.insertGoodsRegion(goodsRegion));
    }

    /**
     * 修改商品禁止发货区域
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        GoodsRegion goodsRegion = goodsRegionService.selectGoodsRegionById(id);
        mmap.put("goodsRegion", goodsRegion);
        return prefix + "/edit";
    }

    /**
     * 修改保存商品禁止发货区域
     */
    @RequiresPermissions("system:goodsregion:edit")
    @Log(title = "商品禁止发货区域", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(GoodsRegion goodsRegion)
    {
        return toAjax(goodsRegionService.updateGoodsRegion(goodsRegion));
    }

    /**
     * 删除商品禁止发货区域
     */
    @RequiresPermissions("system:goodsregion:remove")
    @Log(title = "商品禁止发货区域", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(goodsRegionService.deleteGoodsRegionByIds(ids));
    }
}
